package com.wenhai.springbook.lookupmethod;

import org.springframework.beans.factory.support.MethodReplacer;

import java.lang.reflect.Method;
import java.util.Arrays;

public class MyReplaceMethod implements MethodReplacer {
    @Override
    public Object reimplement(Object obj, Method method, Object[] args) throws Throwable {
        System.out.println(Arrays.toString(args));
        System.out.println("我替换了原有的方法");
        System.out.println(obj.getClass().getGenericSuperclass().getTypeName());
        Object o = Class.forName(obj.getClass().getGenericSuperclass().getTypeName()).newInstance();
        method.invoke(o, args);
        return null;
    }

    public void replaceShowMe(String name) {
        System.out.println(name + " MyChange");
    }
}

